﻿Imports Infragistics.WebUI.Shared
Imports Infragistics.WebUI.WebSchedule
Public Class Appt
    Inherits System.Web.UI.Page
    Private et As New ETModelContainer
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load




        Dim result = et.MyUnitPermissions(User.Identity.Name)

        Dim x = From y In result Where y.RoleName = UNIT_SCHEDULER

        cboCalendar.DataSource = x
        cboCalendar.DataTextField = "OrganizationName"
        cboCalendar.DataValueField = "OrganizationID"
        cboCalendar.DataBind()

    End Sub

    Protected Sub cmdSave_Click(sender As Object, e As EventArgs) Handles cmdSave.Click

        Dim a As New Infragistics.WebUI.WebSchedule.Appointment(WebScheduleInfo1)
        a.StartDateTime = New SmartDate(datStart.Value.ToString)
        a.EndDateTime = New SmartDate(datEnd.Value.ToString)
        a.Subject = txtName.Text

        Dim rs As ICollection = WebScheduleSqlClientProvider1.FetchResources
        Dim r As Resource = Nothing
        For Each i As Resource In rs
            If i.Name = cboCalendar.SelectedValue Then
                r = i
                Exit For
            End If
        Next

        If r Is Nothing Then
            r = New Resource()
            r.Description = cboCalendar.SelectedValue
            r.Name = cboCalendar.SelectedItem.Text
            WebScheduleSqlClientProvider1.AddResource(r)

        End If


        WebScheduleSqlClientProvider1.AddActivity(a, r)


        et.OrganizationActivityAssign(CType(a.DataKey, Integer?), CType(cboCalendar.SelectedValue, Integer?))

    End Sub
End Class